// window.onload = () => {
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var windowScaleFactor = window.outerWidth / window.innerWidth;

window.addEventListener('resize', function () {
    windowScaleFactor = window.outerWidth / window.innerWidth;
});

//插入一个跟随鼠标的窗口,并设置样式
const mouseWindow = document.createElement('div');
mouseWindow.className = 'mouse-window';
mouseWindow.style.width = 'fix-content';
mouseWindow.style.height = '40px';
mouseWindow.style.backgroundColor = '#fff';
mouseWindow.style.border = '1px solid #ccc';
mouseWindow.style.display = 'flex';
mouseWindow.style.justifyContent = 'center';
mouseWindow.style.alignItems = 'center';
mouseWindow.style.cursor = 'pointer';
mouseWindow.style.userSelect = 'none';
mouseWindow.style.pointerEvents = 'none';
mouseWindow.style.zIndex = '9999';
mouseWindow.style.position = 'fixed';
mouseWindow.style.top = '0';
mouseWindow.style.left = '0';
mouseWindow.style.paddingInline = '10px';
mouseWindow.innerText = '鼠标悬浮此处';
document.body.appendChild(mouseWindow);
//窗口跟随鼠标
document.addEventListener('mousemove', (e) => {
    mouseWindow.style.left = (e.clientX + 10) + 'px';
    mouseWindow.style.top = (e.clientY + 10) + 'px';
});

//自动化生码--获取'插入文件'按钮在浏览器上面的坐标
const insertFileBtnMonitor = setInterval(() => {
    if (document.querySelector("#topNavWrapper > ul > li:nth-child(4) > i") != null) {
        clearInterval(insertFileBtnMonitor)
        setTimeout(() => {
            const ele = document.querySelector("#topNavWrapper > ul > li:nth-child(4) > i");
            window.creatQR_API.sendInsertFileBtnPoint(
                ele.getBoundingClientRect().left * windowScaleFactor + ele.clientWidth / 2,
                ele.getBoundingClientRect().top * windowScaleFactor + ele.clientHeight/2);
        }, 1000);
    }
}, 800);

const aaa = setInterval(async () => {
    var routeFileName = await window.creatQR_API.getRouteFilePath();
    console.log(routeFileName);
    document.querySelectorAll("p").forEach((ele) => {

        if (ele.innerText === routeFileName) {
            clearInterval(aaa);
            document.querySelectorAll("span").forEach((ele) => {
                if (ele.innerHTML.indexOf("禁止下载") === 0) {
                    ele.click();
                }
            });
            document.querySelectorAll("span").forEach((ele) => {
                if (ele.innerHTML === "确 定") {
                    ele.click();
                }
            });
            document.querySelector("#__firstGenerateCode").click();
            const bbb = setInterval(() => {
                document.querySelectorAll("span").forEach((ele) => {
                    if (ele.innerHTML.indexOf("下载图片") === 0) {
                        clearInterval(bbb);
                        setTimeout(() => { ele.click() }, 1500);
                    }
                });
            }, 500);
        }
    })
}, 500);



/** const aaele=document.querySelector("#topNavWrapper > ul > li:nth-child(4) > i");
// const mouseWindow = document.createElement('div');
// mouseWindow.className = 'mouse-window';
// mouseWindow.style.width = 'fix-content';
// mouseWindow.style.height = '40px';
// mouseWindow.style.backgroundColor = '#fff';
// mouseWindow.style.border = '1px solid #ccc';
// mouseWindow.style.display = 'flex';
// mouseWindow.style.justifyContent = 'center';
// mouseWindow.style.alignItems = 'center';
// mouseWindow.style.cursor = 'pointer';
// mouseWindow.style.userSelect = 'none';
// mouseWindow.style.pointerEvents = 'none';
// mouseWindow.style.zIndex = '9999';
// mouseWindow.style.position = 'fixed';
// mouseWindow.style.top = '0';
// mouseWindow.style.left = '0';
// mouseWindow.style.paddingInline = '10px';

// document.body.appendChild(mouseWindow);
// //窗口跟随鼠标
// document.addEventListener('mousemove', (e) => {
//     mouseWindow.style.left = (e.clientX + 10) + 'px';
//     mouseWindow.style.top = (e.clientY + 10) + 'px';
//     mouseWindow.innerText = 'x:'+aaele.getBoundingClientRect().x+'==y:'+aaele.getBoundingClientRect().y+'\n\nmX:'+e.clientX+'==mY:'+e.clientY;
// });**/